#Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=beautifulsoup4
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-beautifulsoup4" "${MINGW_PACKAGE_PREFIX}-python2-beautifulsoup4")
pkgver=4.6.0
pkgrel=1
pkgdesc="A Python HTML/XML parser designed for quick turnaround projects like screen-scraping (mingw-w64)"
arch=('any')
url="https://www.crummy.com/software/BeautifulSoup/index.html"
license=('PSF')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools" "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest" "${MINGW_PACKAGE_PREFIX}-python2-pytest")
source=("https://www.crummy.com/software/BeautifulSoup/bs4/download/${pkgver%.*}/${_realname#*-}-${pkgver}.tar.gz")
sha256sums=('808b6ac932dccb0a4126558f7dfdcf41710dd44a4ef497a0bb59a77f9f078e89')

prepare() {
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done 
}

#check() {
#  cd "$srcdir"/python3-build-${CARCH}
#  ${MINGW_PREFIX}/bin/py.test.exe

#  cd "$srcdir"/python2-build-${CARCH}
#  ${MINGW_PREFIX}/bin/py.test2.exe
#}

package_python3-beautifulsoup4() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python3-chardet: to autodetect character encodings"
              "${MINGW_PACKAGE_PREFIX}-python3-lxml: alternative HTML parser"
              "${MINGW_PACKAGE_PREFIX}-python3-html5lib: alternative HTML parser")

 cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_python2-beautifulsoup4() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python2-chardet: to autodetect character encodings"
              "${MINGW_PACKAGE_PREFIX}-python2-lxml: alternative HTML parser"
              "${MINGW_PACKAGE_PREFIX}-python2-html5lib: alternative HTML parser")


  cd "${srcdir}/python2-build-${CARCH}"

  rm -f ./buildutils/include_win32/stdint.h
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_mingw-w64-i686-python2-beautifulsoup4() {
  package_python2-beautifulsoup4
}

package_mingw-w64-i686-python3-beautifulsoup4() {
  package_python3-beautifulsoup4
}

package_mingw-w64-x86_64-python2-beautifulsoup4() {
  package_python2-beautifulsoup4
}

package_mingw-w64-x86_64-python3-beautifulsoup4() {
  package_python3-beautifulsoup4
}

